package com.arithmeticEveryDay.blueBridge;

import java.util.Scanner;

/*
            *           *                   *
        0   1   2   3   4   5   6   7   8   9   10  11
        0   0   0   0   0   0   0   0   0   0   0   0
0(1, 3) 0   0   3   6   6   9   12  15  18  18  21  24
1(2, 7) 0   0   3   7   7   10  14  17  21  21  24  28
2(4,20) 0   0   3   7   7   10  20  23  27  27  30  40

dp[i][j]:计划天数为j，安排[0, i]的健身任务的最优方案
dp[i][j] = max(dp[i-1][j], value[i-1] + dp[i][j-weight[i-1]])
但健身任务不可中断，上面这样是有问题的
这里把问题分为被其它计划日切断的几段可安排健身的时间
这里1，4，9都是其它计划日，把时间分为三份[2, 3], [5, 8], [10, 11]
对这三个时间段分别进行完全背包再把增益加在一起即可


10 3 3
1 4 9
0 3
1 7
2 20

 */
public class Main5130 {
    int n;
    int[] otherPlanDays;
    int[] practiceTimeExponent;
    int[] practiceBuff;
    long[] practiceTime;

    private Main5130(int n, int[] otherPlanDays, int[] practicePlanTimeIndex, int[] practicePlanBuff) {
        super();
        this.n = n;
        this.otherPlanDays = otherPlanDays;
        this.practiceTimeExponent = practicePlanTimeIndex;
        this.practiceBuff = practicePlanBuff;
        int m = practiceTimeExponent.length;
        practiceTime = new long[m];
        for (int i = 0; i < m; i++) {
            practiceTime[i] = quickPow(2, practiceTimeExponent[i]);
            // System.out.println(practiceTime[i]);
        }
    }
    private long maxBuffSum() {
        int begin = 0;
        long buffSum = 0;
        for (int i = 0; i < otherPlanDays.length; i++) {
            buffSum += getMaxBuffSum(otherPlanDays[i] - begin);
            begin = otherPlanDays[i];
        }
        buffSum += getMaxBuffSum(n+1 - begin);
        return buffSum;
    }
    public long getMaxBuffSum(int daysNum) {
        if (daysNum == 0) {
            return 0;
        }
        int m = practiceTimeExponent.length;
        long[][] dp = new long[m+1][daysNum];
        
        for (int i = 1; i <= m; i++) {
            for (int j = 0; j < daysNum; j++) {
                if (j >= practiceTime[i-1]) {
                    dp[i][j] = Math.max(dp[i-1][j], practiceBuff[i-1] + dp[i][(int) (j-practiceTime[i-1])]);
                } else {
                    dp[i][j] = dp[i-1][j];
                }
            }
        }
        /*
        for (int i = 0; i <= m; i++) {
            System.out.println(Arrays.toString(dp[i]));
        }
        */
        // System.out.println(dp[m][daysNum-1]);
        return dp[m][daysNum-1];
    }

    private int quickPow(int i, int j) {
        if (j == 0) {
            return 1;
        }
        int result = 1;
        int temp = quickPow(i, j/2);
        result *= temp * temp;
        if (j % 2 != 0) {
            result *= i;
        }
        return result;
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int q = scan.nextInt();
        int[] otherPlanDays = new int[q];
        int[] practiceTimeExponent = new int[m];
        int[] practicePlanBuff = new int[m];
        for (int i = 0; i < q; i++) {
            otherPlanDays[i] = scan.nextInt();
        }
        for (int i = 0; i < m; i++) {
            practiceTimeExponent[i] = scan.nextInt();
            practicePlanBuff[i] = scan.nextInt();
        }
        Main5130 main = new Main5130(n, otherPlanDays, practiceTimeExponent, practicePlanBuff);
        System.out.println(main.maxBuffSum());
    }

    

}
